﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using WebApp.Services;

namespace WebApp.Controllers
{
    [Produces("application/json")]
    [Route("api/RedisCache")]
    public class RedisCacheController : Controller
    {
        private readonly RedisCacheService _redisCacheService;
        private readonly ILogger<RedisCacheController> _logger;
        public RedisCacheController(RedisCacheService redisCacheService, ILogger<RedisCacheController> logger)
        {
            _redisCacheService = redisCacheService;
            _logger = logger;
        }



        // GET api/values/key
        [HttpGet("{key}")]
        public string Get(string key)
        {
            _logger.LogInformation($"RedisCacheService LogInformation key:{key},datetime:{DateTime.Now.Ticks}");
            _logger.LogDebug($"RedisCacheService LogDebug key:{key},datetime:{DateTime.Now.Ticks}");
            _logger.LogError($"RedisCacheService LogError key:{key},datetime:{DateTime.Now.Ticks}");
            _logger.LogWarning($"RedisCacheService LogWarning key:{key},datetime:{DateTime.Now.Ticks}");
        

            return _redisCacheService.Get(key)?.ToString() ?? "null";
        }


        // POST api/values
        [HttpPost]
        public void Post([FromBody]string key)
        {
            _redisCacheService.Add(key, DateTime.Now.Ticks);

        }


    }
}